﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DB_test.Models
{
    static class JumpMap
    {
        public static void RemoveJump(Jump jump)
        {
            var removeString = String.Format("delete from jumps where {0}='{1}'", Jump.GetIdField(), jump.Id);
            MyDbConnection.ExecuteUpdate(removeString);
        }

        public static void SaveJumpToDatabase(Jump jump)
        {
            var existingJump = MyDbConnection.ReadFromDataBase(String.Format("select * from jumps where {0}={1}", Jump.GetIdField(), jump.Id));
            var data = jump.GetDictionary();
            if (existingJump.Count == 0) // New Jump;
            {
                var insertString = String.Format("insert into jumps {0}", GenerateSqlQuerys.InsertQuery(data, Jump.GetIdField()));
                jump.Id = MyDbConnection.ExecuteInsert(insertString);
            }
            else // Existing Jump
            {
                var updateString = String.Format("update jumps set {0}", GenerateSqlQuerys.UpdateQuery(data, Jump.GetIdField()));
                MyDbConnection.ExecuteUpdate(updateString);
            }
        }

    }
}
